package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Chinanewsnews;
import com.ruoyi.system.service.IChinanewsnewsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中国新闻信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-02
 */
@Controller
@RequestMapping("/system/chinanewsnews")
public class ChinanewsnewsController extends BaseController
{
    private String prefix = "system/chinanewsnews";

    @Autowired
    private IChinanewsnewsService chinanewsnewsService;

    @RequiresPermissions("system:chinanewsnews:view")
    @GetMapping()
    public String chinanewsnews()
    {
        return prefix + "/chinanewsnews";
    }

    /**
     * 查询中国新闻信息列表
     */
    @RequiresPermissions("system:chinanewsnews:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Chinanewsnews chinanewsnews)
    {
        startPage();
        List<Chinanewsnews> list = chinanewsnewsService.selectChinanewsnewsList(chinanewsnews);
        return getDataTable(list);
    }

    /**
     * 导出中国新闻信息列表
     */
    @RequiresPermissions("system:chinanewsnews:export")
    @Log(title = "中国新闻信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Chinanewsnews chinanewsnews)
    {
        List<Chinanewsnews> list = chinanewsnewsService.selectChinanewsnewsList(chinanewsnews);
        ExcelUtil<Chinanewsnews> util = new ExcelUtil<Chinanewsnews>(Chinanewsnews.class);
        return util.exportExcel(list, "中国新闻信息数据");
    }

    /**
     * 新增中国新闻信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存中国新闻信息
     */
    @RequiresPermissions("system:chinanewsnews:add")
    @Log(title = "中国新闻信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Chinanewsnews chinanewsnews)
    {
        return toAjax(chinanewsnewsService.insertChinanewsnews(chinanewsnews));
    }

    /**
     * 修改中国新闻信息
     */
    @RequiresPermissions("system:chinanewsnews:edit")
    @GetMapping("/edit/{newsId}")
    public String edit(@PathVariable("newsId") Long newsId, ModelMap mmap)
    {
        Chinanewsnews chinanewsnews = chinanewsnewsService.selectChinanewsnewsByNewsId(newsId);
        mmap.put("chinanewsnews", chinanewsnews);
        return prefix + "/edit";
    }

    /**
     * 修改保存中国新闻信息
     */
    @RequiresPermissions("system:chinanewsnews:edit")
    @Log(title = "中国新闻信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Chinanewsnews chinanewsnews)
    {
        return toAjax(chinanewsnewsService.updateChinanewsnews(chinanewsnews));
    }

    /**
     * 删除中国新闻信息
     */
    @RequiresPermissions("system:chinanewsnews:remove")
    @Log(title = "中国新闻信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chinanewsnewsService.deleteChinanewsnewsByNewsIds(ids));
    }
}
